#include <iostream>
#include <thread>
#include <mutex>

class SafeCounter
{
public:
    SafeCounter() : value(0) {}

    void increment()
    {
        std::lock_guard<std::mutex> lock(mutex_);
        ++value;
    }

    int getValue()
    {
        std::lock_guard<std::mutex> lock(mutex_);
        return value;
    }

private:
    int value;
    std::mutex mutex_;
};

int main()
{
    SafeCounter counter;

    auto increment_func = [&counter]()
    {
        for (int i = 0; i < 100000; ++i)
        {
            counter.increment();
        }
    };

    std::thread t1(increment_func);
    std::thread t2(increment_func);

    t1.join();
    t2.join();

    std::cout << "Final value: " << counter.getValue() << std::endl;

    return 0;
}
